Skip to content

Conversation

SparkyPotato
Copy link
Contributor

@SparkyPotato SparkyPotato commented Jul 16, 2025

Objective

Optimizes the initial + temporal ReSTIR DI pass. In the example cornell box scene, it goes from 2.37 ms to 1.97 ms. On a more complex scene, the Lumberyard bistro, with many emissive lights, it goes from 130+ ms to about 80.8 ms at 1440p on a 4070.

I also noticed that triangle area calculation didn't take object scale into account and fixed that.

Solution

  • Switch to textures instead of buffers for reservoir storage.
  • There's also a bunch of other micro-optimizations to increase SM occupancy and reduce memory pressure.

Testing

  • This was tested on the cornell box example scene and bistro.
  • Everything was tested on Windows 11 with a 4070 running at 1440p. Testing on other platforms and GPUs by running the example.

Showcase

image

@JMS55 JMS55 self-requested a review July 16, 2025 00:28
@alice-i-cecile alice-i-cecile added this to the 0.17 milestone Jul 16, 2025
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times labels Jul 16, 2025
@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward M-Needs-Release-Note Work that should be called out in the blog due to impact labels Jul 16, 2025
@alice-i-cecile
Copy link
Member

Please add this PR (and yourself!) to the draft release notes :)

@JMS55
Copy link
Contributor

JMS55 commented Jul 20, 2025

Lets hold off on this until #20213 is merged.

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 29, 2025
@alice-i-cecile
Copy link
Member

@SparkyPotato the linked PR is merged; could you resolve conflicts and merge main in please?

@JMS55
Copy link
Contributor

JMS55 commented Jul 31, 2025

I'm getting instant NaNs with this PR :(

@SparkyPotato SparkyPotato removed the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label Jul 31, 2025
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Jul 31, 2025
if reservoir_valid(reservoir) {
let inverse_target_function = select(0.0, 1.0 / reservoir_target_function, reservoir_target_function > 0.0);
reservoir.unbiased_contribution_weight = weight_sum * inverse_target_function;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add back the newline please

return empty_reservoir();
}
temporal_reservoir.sample.light_id = (light_id << 16u) | triangle_id;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@JMS55
Copy link
Contributor

JMS55 commented Aug 2, 2025

error: no definition in scope for identifier: `instance_geometry_ids`
    ┌─ embedded://bevy_solari/scene/raytracing_scene_bindings.wgsl:214:119
    │
214 │     return ResolvedRayHitFull(world_position, world_normal, geometric_world_normal, world_tangent, uv, triangle_area, instance_geometry_ids.triangle_count, resolved_material);
    │                                                                                                                       ^^^^^^^^^^^^^^^^^^^^^ unknown identifier
    │
    = no definition in scope for identifier: `instance_geometry_ids`
    ```

Copy link
Member

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool. Surprised how big a win this is.

@JMS55 JMS55 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 7, 2025
@alice-i-cecile
Copy link
Member

@SparkyPotato ready to merge once conflicts are resolved :)

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Aug 9, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Aug 9, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Aug 10, 2025
Merged via the queue into bevyengine:main with commit dfd10f1 Aug 10, 2025
32 checks passed
gwafotapa pushed a commit to gwafotapa/bevy that referenced this pull request Aug 12, 2025
# Objective
Optimizes the initial + temporal ReSTIR DI pass. In the example cornell
box scene, it goes from 2.37 ms to 1.97 ms. On a more complex scene, the
Lumberyard bistro, with many emissive lights, it goes from 130+ ms to
about 80.8 ms at 1440p on a 4070.

I also noticed that triangle area calculation didn't take object scale
into account and fixed that.

## Solution
- Switch to textures instead of buffers for reservoir storage.
- There's also a bunch of other micro-optimizations to increase SM
occupancy and reduce memory pressure.

## Testing

- This was tested on the cornell box example scene and bistro.
- Everything was tested on Windows 11 with a 4070 running at 1440p.
Testing on other platforms and GPUs by running the example.

---

## Showcase

<img width="2560" height="1392" alt="image"
src="https://github.com/user-attachments/assets/b53f66e8-c97d-4f94-b30f-bbe6ade1a507"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Performance A change motivated by improving speed, memory usage or compile times M-Needs-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants